package com.sunnyebuy.merchant.interceptor;

import java.util.Map;

import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;

/**
 * <p>
 * Title: TrimInterceptor.java
 * </p>
 * 
 * <p>
 * Description: com.sunnyebuy.merchant.interceptor
 * </p>
 * 
 * <p>
 * Copyright: Copyright (c) 2008-2011 All rights reserved.
 * </p>
 * 
 * <p>
 * Created: 2011-12-28 上午11:27:06
 * </p>
 * 
 * @author Wenzhong Gu
 * 
 * @version 1.0
 */
public class TrimInterceptor extends AbstractInterceptor {

	private static final long serialVersionUID = 4146521701250932074L;

	@Override
	public String intercept(ActionInvocation actionInvocation) throws Exception {
		Map<String, Object> parameters = actionInvocation.getInvocationContext().getParameters();
		for (String key : parameters.keySet()) {
			Object value = parameters.get(key);
			if (value instanceof String[]) {
				String[] values = (String[]) value;
				for (int i = 0; i < values.length; i++) {
					values[i] = values[i].trim();
				}
				parameters.put(key, values);
			}
		}
		return actionInvocation.invoke();
	}
}